package com.example.demo.controller;

import com.example.demo.entity.QUERY.WeConDepartmentQuery;
import com.example.demo.entity.VO.WeConDepartmentVO;
import com.example.demo.service.weCon.ContactsManagementService;
import com.example.demo.utils.DiyBeanUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author jack
 * @data 2021/8/13 10:52 上午
 */
@Api(value = "通讯录管理")
@RestController
public class WeConController {

  @Autowired
  private ContactsManagementService contactsManagementService;

  @ApiOperation(value = "获取企业活跃成员数", tags = "成员管理")
  @ApiImplicitParam(value = "日期", name = "date")
  @GetMapping("getActiveStat")
  public Integer getActiveStat(String date) {
    return contactsManagementService.getActiveStat(date);
  }

  @ApiOperation(value = "获取加入企业二维码", tags = "成员管理")
  @GetMapping("getJoinQrcode")
  public String getJoinQrcode() {
    return contactsManagementService.getJoinQrcode();
  }

  @ApiOperation(value = "获取部门列表", tags = "部门管理")
  @GetMapping(value = {"listDepartment/{id}", "listDepartment"})
  public List<WeConDepartmentVO> listDepartment(
      @PathVariable(value = "id", required = false)
          Integer id) {
    return DiyBeanUtils
        .entityListToModelList(contactsManagementService.listDepartment(id),
            WeConDepartmentVO.class);

  }


  @ApiOperation(value = "创建部门", tags = "部门管理")
  @GetMapping("department/create")
  public String createDepartment(@Valid WeConDepartmentQuery weConDepartmentQuery) {
    throw new RuntimeException("自定义异常");
//    contactsManagementService.createDepartment(weConDepartmentQuery);
//    return "ok";
  }

  @ApiOperation(value = "修改部门", tags = "部门管理")
  @GetMapping("department/update")
  public String updateDepartment(@Valid WeConDepartmentQuery weConDepartmentQuery) {
    contactsManagementService.updateDepartment(weConDepartmentQuery);
    return "ok";
  }

  @ApiOperation(value = "删除部门", tags = "部门管理")
  @GetMapping("department/delete/{id}")
  public String updateDepartment(
      @PathVariable("id")
          Integer id) {
    contactsManagementService.deleteDepartment(id);
    return "ok";
  }


}
